package com.qf.lanzhou.blog.api.service.impl;

import com.qf.lanzhou.blog.api.dao.Impl.PraiseArticleDaoimpl;
import com.qf.lanzhou.blog.api.dao.Impl.PraiserInsertDaoimpl;
import com.qf.lanzhou.blog.api.dao.PraiseArticleDao;
import com.qf.lanzhou.blog.api.dao.PraiserInsertDao;
import com.qf.lanzhou.blog.api.pojo.entity.Praise;
import com.qf.lanzhou.blog.api.service.PraiserInsertService;

import java.util.List;

/**
 * @Author jian
 * @Date 2020/12/17 14:58
 * @JDK 1.8
 * @Version 1.0
 */
public class PraiserInsertServiceimpl implements PraiserInsertService {
    private PraiserInsertDao pDao=new PraiserInsertDaoimpl();
    @Override
    public List<Praise> selectPraiser(String userId, String articleId, String praiseStatus) {
        return pDao.select(praiseStatus);
    }

    @Override
    public int addPraiser(String userId, String articleId, String praiseStatus) {
        return pDao.insert(userId,articleId,praiseStatus);
    }

    @Override
    public Praise checkPraiser(String userId, String articleId) {
        PraiseArticleDao praiseArticle=new PraiseArticleDaoimpl();
        return praiseArticle.selectByUserIdAndArticleId(userId,articleId);
    }

    @Override
    public Boolean praise(String userId, String articleId) {
        int update = pDao.update(userId, articleId);
        if(update!=1){
            throw new RuntimeException("系统繁忙，点赞失败");
        }
        return true;
    }
}
